﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WHC.Hotel.BLL;
using WHC.OrderWater.Commons;


namespace WHC.Hotel.UI.Report
{
    public partial class KTVConsumptionCateReport : BaseForm
    {
        public KTVConsumptionCateReport()
        {
            InitializeComponent();
        }

        private void InitDictItem()
        {
        }

        private void KFTopTradeReport_Load(object sender, EventArgs e)
        {
            InitDictItem();
            this.dtStart.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
            this.dtEnd.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));

        }

        private void BindItemCateData()
        {
            #region 条件检索

            SearchCondition condition = new SearchCondition();
            condition.AddCondition("BeginTime", this.dtStart.Value.ToString(), SqlOperator.MoreThanOrEqual)
            .AddCondition("BeginTime", this.dtEnd.Value.ToString(), SqlOperator.LessThanOrEqual);
            string filter = condition.BuildConditionSql(DatabaseType.SqlServer);

            #endregion

            DataTable dt = BLLFactory<TeaConsumerList>.Instance.GetCategoryTradeReport(filter);

            #region 增加汇总信息
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.NewRow();
                dr["ItemType"] = string.Format("合计:");
                decimal Quantity = 0M;
                decimal OriginalAmount = 0M;
                decimal OfferMoney = 0M;
                decimal Amount = 0M;
                foreach (DataRow row in dt.Rows)
                {
                    Quantity += Convert.ToDecimal(row["Quantity"]);
                    OriginalAmount += Convert.ToDecimal(row["OriginalAmount"]);
                    OfferMoney += Convert.ToDecimal(row["OfferMoney"]);
                    Amount += Convert.ToDecimal(row["Amount"]);
                }
                dr["Quantity"] = Quantity;
                dr["OriginalAmount"] = OriginalAmount;
                dr["OfferMoney"] = OfferMoney;
                dr["Amount"] = Amount;

                dt.Rows.Add(dt.NewRow());
                dt.Rows.Add(dt.NewRow());
                dt.Rows.Add(dr);
            }
            #endregion
            this.winGridView1.DataSource = dt.DefaultView;
            this.winGridView1.MergeColumnNames.Add("Column1");
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            BindItemCateData();
        }

        private void menu_InRefresh_Click(object sender, EventArgs e)
        {
            BindItemCateData();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            string title = Portal.gc.gAppUnit + " -- " + "KTV包间消费分类统计报表";
            PrintDGV.Print_DataGridView(this.winGridView1, title);
        }

        private void menu_Print_Click(object sender, EventArgs e)
        {
            btnPrint_Click(null, null);
        }
    }
}
